//
//  KlineLandscapeViewController.swift
//  Exchange
//
//  Created by rui on 2018/4/28.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
import SnapKit

class KlineLandscapeViewController: KlineViewController {
    
    
    weak var fromViewController: KlineViewController?
    
    @IBOutlet weak var varityLabel: UILabel!
    
    @IBOutlet weak var closeBtn: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initUI()
        initData()
    }
    
    override func initData() {
        viewModel.delegate = self
        
    }
    override func initUI() {
        chatView.delegate = self
        self.varityLabel.text = viewModel.coinModel.name
        if ThemeManager.default.currentThemeMode() == .day {
            chatView.style = CHKLineChartStyle.customLight
        }else {
            chatView.style = CHKLineChartStyle.customDark
        }
        for btn in timesArray {
            if btn.title == viewModel.peroid {
                 self.timeClick(btn: btn)
            }
            btn.click = {[weak self](btn) in
                self?.timeClick(btn: btn)
            }
        }
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        if #available(iOS 11.0, *) {
            self.chatView.snp.updateConstraints { (make) in
                make.left.equalToSuperview().offset(self.view.safeAreaInsets.left)
            }
            self.varityLabel.snp.updateConstraints { (make) in
                make.left.equalToSuperview().offset(self.view.safeAreaInsets.left)
            }
            self.closeBtn.snp.updateConstraints { (make) in
                make.right.equalToSuperview().offset(-self.view.safeAreaInsets.right)
            }
        } else {
            // Fallback on earlier versions
        }
    }
    
    @IBAction func dismiss(_ sender: UIButton) {
        
        fromViewController?.viewModel = self.viewModel
        
        self.dismiss(animated: true, completion: nil)
    }

}

extension KlineLandscapeViewController  {
    
    ///当前选中
    override func kLineChart(chart: CHKLineChartView, didSelectAt index: Int, item: CHChartItem) {
        
    }
    
    ///切换分区的k线类型
    override func kLineChart(chart: CHKLineChartView, didFlipPageSeries section: CHSection, series: CHSeries, seriesIndex: Int) {
    }
    
}

extension KlineLandscapeViewController {
    override var shouldAutorotate: Bool {
        get {
            return true
        }
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        get {
            return .landscapeRight
        }
    }
    
    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        get {
            return .landscapeRight
        }
    }
    
    override func prefersHomeIndicatorAutoHidden() -> Bool {
        return true
    }
    
}

